package com.jack.xiaoer.web.controller;

import com.jack.xiaoer.entity.User;
import com.jack.xiaoer.util.AjaxResponse;
import com.jack.xiaoer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


/**
 * Created by Jackaroo Zhang on 2018/11/13.
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResponse getUsers(@PathVariable("id") Long id) {

        return AjaxResponse.success("successful", userService.getUser(id));
    }

    @RequestMapping("/user/view/{id}")
    public ModelAndView userView(@PathVariable("id") Long id) {
        ModelAndView mv = new ModelAndView("home");
        User user = userService.getUser(id);
        mv.addObject("user", user);

        return mv;
    }

}
